#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_uart.h"
#include "iot_gpio.h"
#include "iot_errno.h"
#include "step_motor.h"
#include "myapp_log.h"

static const char *TAG = "MAIN";

#define TASK_STACK_SIZE 1024 * 8
#define TASK_PRIORITY 25

osThreadId_t TASK_ID = NULL;

#define UART_BUFF_SIZE 1000

static void *LedTask(const char *arg)
{
    (void)arg;

    step_motor_init();

    step_monitor_set_dir_up();
    step_monitor_exe_both_step_params_cylce(100, 300);
    step_monitor_set_dir_left();
    step_monitor_exe_both_step_params_cylce(100, 300);
    step_monitor_set_dir_down();
    step_monitor_exe_both_step_params_cylce(100, 300);
    step_monitor_set_dir_right();
    step_monitor_exe_both_step_params_cylce(100, 300);

    return NULL;
}

static void HelloMain(void)
{
    MYAPP_LOGI(TAG,"Program Start");

    // 初始化进程
    osThreadAttr_t attr;
    // 设置进程名称
    attr.name = "LedTask";
    // 设置分离式进程
    attr.attr_bits = 0U;
    // cb控制块指针设置自动管理(空)
    attr.cb_mem = NULL;
    // cb控制块的大小为0
    attr.cb_size = 0U;
    // 栈管理 指针-> NULL 使用线程管理从内存池分配内存
    attr.stack_mem = NULL;
    // 栈大小 单位:字节
    attr.stack_size = TASK_STACK_SIZE;
    // 进程优先级 Normal+1级
    attr.priority = TASK_PRIORITY;

    if (TASK_ID = osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL)
    {
        printf("[LedExample] Failed to create LedTask!\n");
    }
    else
    {
        printf("[LedExample] Success to create LedTask!%d\n", TASK_ID);
    }
}

SYS_RUN(HelloMain);